<template>
    <h2>显示</h2>
    理财名称:<input type="text" v-model="F_Name" id="F_Name">
    <input type="button" value="查询" @click="Show" />
    <table>
        <thead>
            <tr>
                <td>理财名称</td>
                <td>年收益</td>
                <td>理财最低金额</td>
                <td>理财人数</td>
                <td>风险等级</td>
                <td>利息</td>
                <td>操作</td>

            </tr>
        </thead>
        <tbody>
            <tr v-for="item in data" :key="item.F_Id">
                <td>{{ item.F_Name }}</td>
                <td>{{ item.F_APY }}</td>
                <td>{{ item.F_MinMoney }}</td>
                <td>{{ item.F_Num }}</td>
                <td>{{ item.Level }}</td>
                <td>{{ item.I_Id }}</td>
                <td>
                    <input type="button" value="删除" @click="LDel(item.F_Id)" />
                    <input type="button" value="修改" @click="Upa(item.F_Id)" />
                </td>
                <td></td>
            </tr>
        </tbody>
    </table>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { onMounted } from "vue";
import { useRouter } from "vue-router";

import axios from "axios";
const data = ref([{
    F_Name: ref(""),
    F_APY: ref(""),
    F_MinMoney: ref(""),
    F_Num: ref(""),
    F_Level: ref(-1),
    I_Id: ref(0),
}]);
const F_Name = ref("");
onMounted(() => {
    Show()
})
const Show = () => {
    axios.get('http://localhost:15120/api/Demo/ShowFinancing', {
        params: {
            F_Name: F_Name.value,
        }
    }

    )
        .then(res => {
            data.value = res.data;
        })
        .catch(error => {
            console.log(error);
        })
}
const LDel = (F_Id: number) => {
    if (confirm("确定要删除吗？")) {
        axios.get('http://localhost:15120/api/Demo/LDel', {
            params: {
                F_Id: F_Id
            }
        })
            .then(res => {
                if (res.data > 0) {
                    alert("删除成功");
                    Show()
                    return;
                }
                else {
                    alert("删除失败");
                    return;
                }
            })
            .catch(error => {
                console.log(error);
            })

    }

}
const router = useRouter();
const Upa = (F_Id: number) => {
    router.push({
        name: "FUpa",
        params: {
            F_Id: F_Id
        }
    })
}
</script>